package com.sunny.demo2;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class MyProxy<T> {

    public T getProxy(T real){

        T proxy = (T) Proxy.newProxyInstance(real.getClass().getClassLoader(),real.getClass().getInterfaces(),new MyHandler(real));

        return proxy;

    }

}

class MyHandler<T> implements InvocationHandler{

    private T obj;

    public MyHandler(T t){
        obj = t;
    }

    @Override
    public Void invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("param is ");
        for(Object arg: args){

            System.out.print(arg);

        }

        method.invoke(obj,args);

        System.out.println("do after");

        return null;

    }

}
